package com.timeste.lasttime;

import java.util.Date;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;

public class CreateEventActivity extends Activity
{
	private static Context mContext;
	private DatabaseHandler db;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.new_item);
        db = new DatabaseHandler(this);
        
        DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
        datePicker.setMaxDate((new Date()).getTime());
        
    }
    
    public static Context getContext(){
        return mContext;
    }
    
    
	public void createEvent(View view) {
		
		
		EditText titleText = (EditText) findViewById(R.id.editText1);
		String title = titleText.getText().toString();
		EditText descriptionText = (EditText) findViewById(R.id.editText2);
		String description = descriptionText.getText().toString();
		
		DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
		int day = datePicker.getDayOfMonth();
		int month = datePicker.getMonth();
		int year = datePicker.getYear();
		
		LastTimeEvent event = new LastTimeEvent(title, description, year, month, day);
		db.addEvent(event);
		
		Intent intent = new Intent(this, MainActivity.class);
    	startActivity(intent);
        
    }
}
